import {abstractValidator} from "./abstractValidator";
import {mc_validatorResult} from "../model/mc_validatorResult";
import {requireValidator} from "./requireValidator";
import {el} from "@angular/platform-browser/testing/src/browser_util";
/**
 * Created by ybjaa on 2017/6/28.
 */

/**
 * 判断字符串长度是否在该范围内
 */
export class maxAndMinLengthValidator extends abstractValidator{

    protected max:number=0;
    protected min:number=0;


    /**
     *
     * @param min 最小值
     * @param max 最大值
     */
    public setParameters(min:number=0,max:number=0): void {

        if(min>max){
            this.min=max;
            this.max=min;
        }else{
            this.min=min;
            this.max=max;
        }


    }


    protected getValidator(value:string): mc_validatorResult {

        if(typeof(value) != "string"){
            this.setResult(false,"数据类型不对");
            this.result.result=false;
        }

        //判断最大长度
        if(value.length>this.max){
            this.setResult(false,"长度大于"+this.max);
            return this.result;
        }

        //判断最小长度
        if(value.length<this.min){
            this.setResult(false,"长度小于"+this.min);
            return this.result;
        }

        return this.result;
    }

}